package com.ctrip.cap.appium;

import static com.ctrip.cap.Assertion.assertElementPresent;
import io.appium.java_client.AppiumDriver;

import java.util.Set;

import org.openqa.selenium.By;

import com.ctrip.cap.common.exception.CapException;

/**
 * 
 * @author ltyao
 *
 */
public class AppiumUtils {

	public static void setWebView0Context(AppiumDriver driver) {
		assertElementPresent(By.className("android.webkit.WebView"), driver, 30);
		Set<String> contexts = driver.getContextHandles();
		if (contexts.contains("WEBVIEW_0")) {
			driver.context("WEBVIEW_0");
		} else {
			throw new CapException("No WEBVIEW_0 Context Found ");
		}

	}

}
